home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_MakeItem.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  3KB  |  122 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LTP_MakeItem(RootMenu *Root,struct NewMenu *Template):
  14.      *
  15.      *    Create a single menu item and fill it in.
  16.      */
  17.  
  18. ItemNode * __regargs
  19. LTP_MakeItem(RootMenu *Root,struct NewMenu *Template)
  20. {
  21.     ItemNode    *Item;
  22.     LONG         Size;
  23.  
  24.         // Which type of entry to create
  25.  
  26.     if(Template -> nm_Label == NM_BARLABEL)
  27.         Size = sizeof(ItemNode) + sizeof(struct Image);
  28.     else
  29.         Size = sizeof(ItemNode) + sizeof(struct IntuiText);
  30.  
  31.         // Make room for it
  32.  
  33.     if(Item = AsmAllocPooled(Root -> Pool,Size,SysBase))
  34.     {
  35.             // Is it a separator bar?
  36.  
  37.         if(Template -> nm_Label == NM_BARLABEL)
  38.         {
  39.             struct Image *Image = (struct Image *)(Item + 1);
  40.  
  41.                 // Fill in the image data
  42.  
  43.             Image -> LeftEdge    = 2;
  44.             Image -> TopEdge    = 2;
  45.             Image -> Depth        = Root -> DrawInfo -> dri_Depth;
  46.             Image -> PlaneOnOff    = Root -> TextPen;
  47.             Image -> Height        = 2;
  48.  
  49.                 // Now take care of the item itself
  50.  
  51.             Item -> Item . ItemFill = Image;
  52.             Item -> Item . Width    = 2;
  53.             Item -> Item . Height    = 2 + Image -> Height + 2;
  54.             Item -> Flags            = ITEMF_IsBar;
  55.             Item -> Item . Flags    = HIGHNONE;
  56.         }
  57.         else
  58.         {
  59.             struct IntuiText *IntuiText = (struct IntuiText *)(Item + 1);
  60.  
  61.                 // Fill in the label
  62.  
  63.             LTP_InitIText(Root,IntuiText);
  64.  
  65.             IntuiText -> LeftEdge    = 2;
  66.             IntuiText -> TopEdge    = (Root -> ItemHeight - Root -> RPort . TxHeight) / 2;
  67.             IntuiText -> IText        = Template -> nm_Label;
  68.  
  69.                 // Now take care of the item itself
  70.  
  71.             Item -> Item . ItemFill    = IntuiText;
  72.             Item -> Item . Width    = 2 + TextLength(&Root -> RPort,IntuiText -> IText,strlen(IntuiText -> IText)) + 2;
  73.             Item -> Item . Height    = Root -> ItemHeight;
  74.             Item -> Item . Flags    = ITEMTEXT | HIGHCOMP;
  75.  
  76.                 // Is there a command to take care of?
  77.  
  78.             if(Template -> nm_CommKey)
  79.             {
  80.                     // Special command?
  81.  
  82.                 if(Template -> nm_Flags & NM_COMMANDSTRING)
  83.                 {
  84.                     Item -> ExtraLabel    = Template -> nm_CommKey;
  85.                     Item -> Flags        = ITEMF_Command;
  86.                 }
  87.                 else
  88.                 {
  89.                         // Just put in the usual command sequence in there
  90.  
  91.                     Item -> Item . Flags    |= COMMSEQ;
  92.                     Item -> Item . Command     = (BYTE)ToUpper(Template -> nm_CommKey[0]);
  93.                 }
  94.             }
  95.  
  96.                 // Move up for the checkmark
  97.  
  98.             if(Template -> nm_Flags & CHECKIT)
  99.                 Item -> Item . Width += 2 + Root -> CheckWidth;
  100.  
  101.                 // Disable the item if necessary
  102.  
  103.             if(!(Template -> nm_Flags & NM_ITEMDISABLED))
  104.                 Item -> Item . Flags |= ITEMENABLED;
  105.  
  106.                 // Fill in the rest of the flags
  107.  
  108.             Item -> Item . Flags |= Template -> nm_Flags & (CHECKIT | MENUTOGGLE | CHECKED);
  109.  
  110.                 // Take care of the remaining data
  111.  
  112.             Item -> Item . MutualExclude = Template -> nm_MutualExclude;
  113.         }
  114.  
  115.         Item -> UserData = Template -> nm_UserData;
  116.     }
  117.  
  118.     return(Item);
  119. }
  120.  
  121. #endif    /* DO_MENUS */
  122.